package com.atguigu.lease.common.config;

import com.atguigu.lease.common.handler.StgyAdminAuthInterceptor;
import com.atguigu.lease.common.handler.StringToBaseTypeEnumConverterFactory;
import com.atguigu.lease.common.handler.StringToItemTypeEnumConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author LOGIN
 * @title stgyWebMvcConfig
 * @create 2025/6/23 19:26
 * @description
 */
    /*
        WebMvcConfigurer:
            mvc的配置类
            - 可以注册拦截器，Interceptor
            - 可以配置跨域
            - 可以注册视图解析器
            - 可以注册消息转换器。

     */

@Configuration
public class stgyWebMvcConfig implements WebMvcConfigurer {
//    @Autowired
//    StringToItemTypeEnumConverter stringToItemTypeEnumConverter;
//注册工厂对象
    @Autowired
    StringToBaseTypeEnumConverterFactory stringToBaseTypeEnumConverterFactory;
    @Autowired
    StgyAdminAuthInterceptor stgyAdminAuthInterceptor;

    @Override
    public void addFormatters(FormatterRegistry registry) {
            //注册消息转换器
//        registry.addConverter(stringToItemTypeEnumConverter);
        //todo 注册消息转换器工厂
        registry.addConverterFactory(stringToBaseTypeEnumConverterFactory);
    }
    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(stgyAdminAuthInterceptor)
                .addPathPatterns("/admin/**")//配置要拦截的路径 支持ant风格的url地址
                .excludePathPatterns("/admin/login/**","/doc.html");//配置要排除的 不拦截的路径
    }
}
